package com.example.blog.controller;


import com.example.blog.pojo.Blog;
import com.example.blog.service.BlogService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import javax.annotation.Resource;
import java.util.List;

/**
 * name: 东北宋小宝
 * date: 2020/8/11
 */
@Controller
public class IndexShowController {
    @Resource
    private BlogService blogService;
    @Value("${blogpage.index}")
    private int pageNum;
    @GetMapping("/")
    public String toIndex() { return "redirect:/index"; }
    @GetMapping("/index")
    public String index(@RequestParam(name = "page",defaultValue = "1") Integer page, Model model){
        PageInfo pageInfo = blogService.getPage(page, pageNum);
        List<Blog> newBlog = blogService.getBlogOrderBy();
        model.addAttribute("newBlog",newBlog);
        model.addAttribute("pageInfo",pageInfo);
        return "/index";
    }
}
